package com.example.demo.ai.llm.controller;

import com.example.demo.ai.llm.service.LlmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import org.noear.solon.annotation.*;
import org.noear.solon.core.util.MimeType;
import reactor.core.publisher.Flux;

/**
 * @author airhead
 */
@Controller
@Mapping("/llm")
@Api("聊天")
public class LlmController {
  @Inject private LlmService service;

  @ApiOperation("chat")
  @Post
  @Mapping("chat")
  public String chat(String prompt) {
    return service.chat(prompt);
  }

  @Produces(MimeType.TEXT_EVENT_STREAM_UTF8_VALUE)
  @Mapping("stream")
  public Flux<String> stream(String prompt) throws IOException {
    return service.stream(prompt);
  }

  @ApiOperation("functionCall")
  @Post
  @Mapping("functionCall")
  public String functionCall(String prompt) {
    return service.functionCall(prompt);
  }
}
